package com.example.demo.init;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.demo.entity.Storage;
import com.example.demo.service.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class DatabaseInit {

    private static final String COMMODITY_CODE = "C00321";

    @Autowired
    private StorageService storageService;

    @PostConstruct
    public void init() {
        storageService.remove(new LambdaQueryWrapper<Storage>().eq(Storage::getCommodityCode, COMMODITY_CODE));
        Storage storage = new Storage();
        storage.setId(IdUtil.getSnowflakeNextId());
        storage.setCommodityCode(COMMODITY_CODE);
        storage.setCount(100);
        storageService.save(storage);
    }

}
